//  this library.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:hktk_app/model/login/config_model.dart';
import 'package:hktk_app/util/font_util.dart';

// import 'package:hktk_app/util/navigator_util.dart';
import 'package:hktk_app/util/view_util.dart';

/// 验证码登录协议页面
class PhoneAgreementWidget extends StatefulWidget {
  /// 对应的url
  final AppConfig appConfig;

  /// 是否是对话框显示
  final bool? dialogShow;

  /// 字体大小
  final double? fontSize;

  const PhoneAgreementWidget({
    super.key,
    this.dialogShow = false,
    required this.appConfig,
    this.fontSize,
  });

  @override
  State<PhoneAgreementWidget> createState() => _PhoneAgreementWidgetState();
}

class _PhoneAgreementWidgetState extends State<PhoneAgreementWidget> {
  /// 用户协议 的手势
  late TapGestureRecognizer _yhGestureRecognizer;

  /// 隐私协议 的手势
  late TapGestureRecognizer _ysGestureRecognizer;

  @override
  void initState() {
    super.initState();
    _yhGestureRecognizer = TapGestureRecognizer();
    _ysGestureRecognizer = TapGestureRecognizer();
  }

  @override
  void dispose() {
    super.dispose();
    _yhGestureRecognizer.dispose();
    _ysGestureRecognizer.dispose();
  }

  @override
  Widget build(BuildContext context) {
    double textSize = widget.fontSize ?? 14;
    return Text.rich(
      TextSpan(
        children: [
          TextSpan(
              text: widget.dialogShow! ? "请你仔细阅读并同意" : "我已阅读并同意",
              style: FontUtil.fontBlack1(textSize)),
          TextSpan(
            text: "“用户协议”",
            style: FontUtil.fontBlue1(textSize),
            recognizer: _yhGestureRecognizer
              ..onTap = () {
                Navigator.pushNamed(context, "/h5", arguments: {
                  "url": widget.appConfig.yhxy!,
                  "title": "用户协议",
                  "showClose": true,
                });
              },
          ),
          TextSpan(text: "和用户", style: FontUtil.fontBlack1(textSize)),
          TextSpan(
            text: "“隐私政策”",
            style: FontUtil.fontBlue1(textSize),
            recognizer: _ysGestureRecognizer
              ..onTap = () {
                Navigator.pushNamed(context, "/h5", arguments: {
                  "url": widget.appConfig.ysxy!,
                  "title": "隐私协议",
                  "showClose": true,
                });
              },
          ),
          if (widget.dialogShow!)
            TextSpan(
              text: "，点击“确认”，表示你已经阅读并同意以上协议",
              style: FontUtil.fontBlack1(textSize),
            ),
        ],
      ),
    );
  }
}
